package com.gisocn.onemap.net;

import android.util.Log;
import io.reactivex.observers.DisposableObserver;
import retrofit2.HttpException;

/* loaded from: classes2.dex */
public abstract class ApiCallback<M> extends DisposableObserver<M> {
    public abstract void onFailure(String str);

    public abstract void onFinish();

    public abstract void onSuccess(M m);

    @Override // io.reactivex.Observer
    public void onError(Throwable th) {
        th.printStackTrace();
        if (th instanceof HttpException) {
            HttpException httpException = (HttpException) th;
            int code = httpException.code();
            String message = httpException.getMessage();
            Log.e("code:", "" + code);
            if (code == 504) {
                message = "网络不给力";
            }
            onFailure((code == 502 || code == 404) ? "服务器异常，请稍后再试" : "服务器异常，请稍后再试");
        } else {
            onFailure(th.getMessage());
        }
        onFinish();
    }

    @Override // io.reactivex.Observer
    public void onNext(M m) {
        onSuccess(m);
    }

    @Override // io.reactivex.Observer
    public void onComplete() {
        onFinish();
    }
}
